<?php
include_once 'mod.php';
$mod = new mod();
session_start();
if($_SERVER['REQUEST_METHOD']=='POST'){
    $login = $_POST['login'];
    $pwd = $_POST['pwd'];
    if (empty($login)){
        die('用户名为空<a href="login.php">重新登录</a>');
    }
    if (empty($pwd)){
        die('密码为空<a href="login.php">重新登录</a>');
    }
    //连接数据库
    $mysql = $mod->link();
    //执行查的sql语句
    $sql = "select * from user where `login_name` = '$login'";
    $reuslt = $mod->select($mysql,$sql);
    if ($reuslt[0]['login_name'] == $login && $reuslt[0]['password'] == $pwd){
        $_SESSION['name']= $reuslt[0]['name'];
        $a=md5($login.$pwd);
        setcookie('user',$a,time()+3600,'/');
        $_SESSION['user'] = $_COOKIE['user'];

        die('登录成功<a href="index.php">进入首页</a>');
    }else{
        die('账户或者密码错误<a href="login.php">重新登录</a>');
    }
}
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>管理人登录</title>
</head>
<body>
<form action="login.php" method="post">
    <p>用户名:<input type="text" name="login"></p>
    <p>密码:<input type="password" name="pwd"></p>
    <input type="submit" value="登录">
    <button>
        <a href="register.php">注册</a>
    </button>
</form>
</body>
</html>
